// 配置说明 https://pm2.io/doc/en/runtime/reference/ecosystem-file/

const app_name = 'im_dev';
const pm_name = 'statistics';
const path = `/home/long/projects/statistics/${app_name}`;
const dev_path = `/User/longly/projects/running/statistics/${app_name}`;
const config_file = `${app_name}.config.js`;

const pm2 = '`npm config --global get prefix`/pm2';
const install = 'npm install';
const startOrReload = `${pm2} startOrReload ${config_file} -a`;
const post_deploy_script = `${install}  && ${startOrReload}`;

module.exports = {
  /**
   * Application configuration section
   * http://pm2.keymetrics.io/docs/usage/application-declaration/
   */
  apps: [
    {
      name: pm_name,
      script: 'index.js',
      exec_mode: 'cluster_mode',
      instances: 1,
      instance_var: 'INSTANCE_ID',
      node_args: '--max_old_space_size=4096',
      env: {
        APP: pm_name,
        CONFIG: app_name,
      },
      env_production: {
        NODE_ENV: 'production',
      },
      log_date_format: 'YYYY-MM-DD HH:mm.ss.SSS Z',
      log: `~/.pm2/logs/${app_name}.log`,
      merge_logs: true,
    },
  ],

  /**
   * Deployment section
   * http://pm2.keymetrics.io/docs/usage/deployment/
   */
  deploy: {
    production: {
      user: 'long',
      host: '112.74.163.86',
      ref: 'origin/master',
      repo: 'git@gitee.com:longliangyou/statistics.git',
      path: path,
      'pre-setup': `rm -rf ${path}`,
      'post-deploy': post_deploy_script,
    },
    dev: {
      user: 'long',
      host: 'localhost',
      ref: 'origin/dev',
      repo: '.',
      path: dev_path,
      //'pre-setup': `rm -rf ${dev_path}`,
      'post-deploy': post_deploy_script,
    },
  },
};
